# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=virt-manager
pkgver=4.1.0
pkgrel=7
pkgdesc="GUI for managing virtual machines"
url="https://virt-manager.org/"
arch="noarch !s390x !riscv64" # spice-gtk
license="GPL-2.0-or-later"
depends="
	python3
	$pkgname-common
	spice-gtk
	vte3
	py3-cairo
	gtk-vnc>=0.5.2-r2
	gtksourceview4
	"
_common_deps="
	libosinfo
	libvirt-glib
	py3-gobject3
	py3-libvirt
	py3-libxml2
	py3-requests
	qemu-img
	"
_virt_install_deps="xorriso"
makedepends="glib-dev py3-docutils py3-setuptools $_common_deps $_virt_install_deps"
checkdepends="
	libosinfo-dev
	py3-gobject3
	py3-libvirt
	py3-libxml2
	py3-pytest
	py3-requests
	"
subpackages="
	$pkgname-doc
	$pkgname-lang
	$pkgname-pyc
	$pkgname-common
	virt-install:virt_install
	$pkgname-bash-completion
	"
source="
	https://releases.pagure.org/virt-manager/virt-manager-$pkgver.tar.gz
	fix-latest-libvirt-xml-output.patch
	upstream_tests-Fix-host-copy-XML-with-libvirt-10.1.0.patch
	test-cli-Adjust-hotplug-test-for-latest-libvirt.patch
	virtinstall-Fix-location-and-cloud-init-conflict.patch
	0001-virt-install-fix-cloud-init-ssh-keys.patch
	"

# secfixes:
#   2.2.1-r0:
#     - CVE-2019-10183

build() {
	python3 setup.py build
}

check() {
	_skipped_tests="
		not testDASDMdev
		and not testAPQNMdev
		and not testPCIMdev
		and not testPCIMdevNewFormat
		and not testAlterCpuMode
		and not testCLI0001virt_install_many_devices
		and not testCLI0057virt_install_osinfo_url
		and not testCLI0079virt_install_osinfo_url_with_disk
		and not testCLI0114virt_install_osinfo_url_unattended
		and not testCLI0115virt_install_osinfo_unattended_treeapis
		and not testCLI0366virt_xml_add_hostdev_mdev
		and not testCLI0374virt_xml_add_hostdev_mdev_start

		and not testCLI0168virt_install_s390x_cdrom
		and not testCLI0394virt_clone_auto_unmanaged
		and not testCLI0397virt_clone
		and not testCLI0398virt_clone
		and not testCLI0412virt_clone
		and not testCLI0413virt_clone
		and not testCLI0415virt_clone
		and not testCLI0416virt_clone
		and not testCLI0424virt_clone

		and not testCLI0263virt_xml
	"
	python3 -m pytest -k "$(echo $_skipped_tests | tr -d '\n')"
}

package() {
	python3 setup.py --no-update-icon-cache --no-compile-schemas install --root "$pkgdir"
	python3 -m compileall "$pkgdir/usr/share/virt-manager"
}

common() {
	pkgdesc="Common files used by virt-manager and virt-install"
	depends="$_common_deps"
	mkdir -p "$subpkgdir"/usr/share/virt-manager "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/share/virt-manager/virtinst \
		"$subpkgdir"/usr/share/virt-manager
}

virt_install() {
	pkgdesc="Utilities for installing virtual machines"
	depends="$pkgname-common=$pkgver-r$pkgrel $_virt_install_deps"
	mkdir -p "$subpkgdir"/usr/share/virt-manager "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/virt-install \
		"$pkgdir"/usr/bin/virt-clone \
		"$subpkgdir"/usr/bin/
}

pyc() {
	default_pyc
	local IFS='
'
	amove $(find usr/share/virt-manager/virtManager -type d -name __pycache__)
}

sha512sums="
725cb5bcbaebaafae417f95deffb4243ccdad769668cba6e1235f4607e2b29dbd099d2a9a3885981158f53ea854dd71cc29ed9d7557b2791161c13d34f2ef883  virt-manager-4.1.0.tar.gz
3106c7d3d91db6c7fa3208a13869c5a84bb636a261939acd3be0a59ce7196dfa6102ec97372d762d8143cef4a1d0ef1c37f4a107c3826c23ff2ed22c6d57f914  fix-latest-libvirt-xml-output.patch
5c1f5c4ded570f15c5c408d8da68fb9f77774503724ff253c6dd87962bf909305654a63503945678c44c4b6ce9206c7628c7640bddce525abfd1288c48ce2570  upstream_tests-Fix-host-copy-XML-with-libvirt-10.1.0.patch
21febff0bb079af8e9895dda406c24bedef3b68f955e71c466d0c3fa31526a82435c32ac45a449e46345f4934fc08b1354eb48b09f263c9505d24d893d56ffc1  test-cli-Adjust-hotplug-test-for-latest-libvirt.patch
3055c7d306d5fba4df7ede03be8e3da095c0808abc3ed372af87874436af3f05c4f904c7510cfa4d6f6b665d63279c8f2ca9918779dd5fe074993c5049076f95  virtinstall-Fix-location-and-cloud-init-conflict.patch
0782ddbee2a0a8145636913a94d5229a3df98132e3edb93c0a83b8b12c8172ce66e609b4b4a56eb19b2b7bc354a264033e4f744a65a8db2ddf02e2984f0aabef  0001-virt-install-fix-cloud-init-ssh-keys.patch
"
